<?php
/**
 * Model for Settings
 *
 * This file contains the model for settings view
 *
 * Joomla! 1.5 component jhtraq
 * Traq type system for Joomla
 *
 * @version $Id: jhtraq.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 *
 * /administrator/com_jhtraq/models/settings.php
 */
// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');

/**
 * Model for Settings
 */
class JhtraqModelSettings extends JModel {
	/**
	 * @name __construct
	 * @public
	 * @param none
	 * @return null
	 */
    function __construct() {
		parent::__construct();
		$this->db =& JFactory::getDBO();
    }
	
	/**
	 * Get all the settings
	 * 
	 *@return array return an associative array with the pairs setting = value
	 */
    function getConfig()
	{
		$this->db->setQuery("Select `setting`,`value` from #__jhtraq_settings");
		$list =  $this->db->loadAssocList();
		$return = array();
		foreach($list as $item)
		{
			$return[$item['setting']] = $item['value'];
		}
		return $return;
	}

    /**
     * Save the givem settings
     *  
     * @param $cfg array And associative array with the settings to save
     */
	function saveConfig($cfg)
	{
		foreach($cfg as $k=>$v)
		{
			$this->db->setQuery("Update #__jhtraq_settings set `value`='".$this->db->getEscaped($v)."' where `setting`='$k'");
			$this->db->query();
		}
	}
}	
?>